package com.zjitc;

import com.zjitc.dao.CatDao;
import com.zjitc.model.Cat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Random;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by 冷丶 on 2018/4/16.
 */
@Service
public class InsertSql {

  @Autowired
  private CatDao catDao;

  /*public static void main(String[] args) {

//    List<Cat> catList = new ArrayList<>();
    List list = new ArrayList();
    list.add("英短");
    list.add("美短");
    list.add("暹罗");
    list.add("阿比");
    list.add("褴褛");
    list.add("布偶");
    for (int i = 0; i < 300; i++) {
      Cat cat = new Cat();
      //id
      cat.setId(i + 1801190000);
      //birthday
      int year = 2018;
      int month = 1 + new Random().nextInt(4);
      int day = new Random().nextInt(30);
      String string = year + "-0" + month + "-" + day;
      SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
      try {
        Date date = sf.parse(string);
//        cat.setBirthday(date);

      } catch (ParseException e) {
        e.printStackTrace();
      }
      //UpdateTime
//      cat.setUpdateTime(new Date());


      *//*随即生成整数*//*
      //int randNumber = new Random().nextInt(100-0+1)+0;
      //user.setAge(randNumber);
      int count = (int) (Math.random() * list.size());
      cat.setCatSpecies(String.valueOf(list.get(count)));
      //Vaccine
      if (month <= 2) {
        cat.setVaccine(0);
      } else {
        cat.setVaccine(2);
      }
      if (month >= 3) {
        cat.setExpellingParasite("一次");
      } else {
        cat.setExpellingParasite("月份不足");
      }
      //sex
      if (i % 2 == 0) {
        cat.setSex("公");
      } else {
        cat.setSex("母");
      }

      //catSpecies
      System.out.println(cat);
//      catList.add(cat);
      CatDao catDao1 =

    }*/


  public void insert() {
    /*List<Cat> catList = new ArrayList<>();
    List list = new ArrayList();
    list.add("英短");
    list.add("美短");
    list.add("暹罗");
    list.add("阿比");
    list.add("褴褛");
    list.add("布偶");
    for (int i = 0; i < 30; i++) {
      Cat cat = new Cat();
      cat.setCatName("a");
      cat.setImage("a");
      cat.setBloodliness("s");
      //id
      cat.setId(i + 1801190000);
      //birthday
      int year = 2018;
      int month = 1 + new Random().nextInt(4);
      int day = new Random().nextInt(30);
      String string = year + "-0" + month + "-" + day;
      SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
      try {
        Date date = sf.parse(string);
        cat.setBirthday(date);
      } catch (ParseException e) {
        e.printStackTrace();
      }
      //UpdateTime
      cat.setUpdateTime(new Date());

      *//*随即生成整数*//*
      //int randNumber = new Random().nextInt(100-0+1)+0;
      //user.setAge(randNumber);
      int count = (int) (Math.random() * list.size());
      cat.setCatSpecies(String.valueOf(list.get(count)));
      //Vaccine
      if (month <= 2) {
        cat.setVaccine(0);
      } else {
        cat.setVaccine(2);
      }
      if (month >= 3) {
        cat.setExpellingParasite("一次");
      } else {
        cat.setExpellingParasite("月份不足");
      }
      //sex
      if (i % 2 == 0) {
        cat.setSex("公");
      } else {
        cat.setSex("母");
      }

      //catSpecies
//      System.out.println(cat);
      catList.add(cat);
      //catDao.addCats(cat);

    }
catDao.findByCatSpecies("英短");
    int c = catDao.addCats(catList);
    System.out.println(c);*/

  }
}
  /*

    @Override
    public List<User> findByDataBase() {
      return userDao.findByDataBase();
    }

    @Override
    public List<User> findAllUser() {
      Jedis jedis = new Jedis("localhost");
      List<User> users = userDao.findAllUser();
      final String KEY_SEX_N="KEY_SEX_N";
      final String KEY_AGE_LARGER_45="KEY_AGE_LARGER_45";
      users.forEach((item)->{
        HashMap<String,String> map = new HashMap<>();
        map.put("age", String.valueOf(item.getAge()));
        map.put("sex", item.getSex());
        jedis.hmset(String.valueOf(item.getId()),map);
        if (item.getAge()>=45){
          jedis.sadd(KEY_AGE_LARGER_45, String.valueOf(item.getId()));
        }
        if (item.getSex().equals("n")){
          jedis.sadd(KEY_SEX_N, String.valueOf(item.getId()));
        }
      });

      Set<String> sinter= jedis.sinter(KEY_SEX_N,KEY_AGE_LARGER_45);
      System.out.println(sinter);
      Set<String> sdiff=jedis.sdiff(KEY_SEX_N,KEY_AGE_LARGER_45);
      System.out.println(sdiff);
      Set<String> sunion=jedis.sunion(KEY_SEX_N,KEY_AGE_LARGER_45);
      System.out.println(sunion);

      sinter.forEach(item->{
        Map<String, String> stringStringMap = jedis.hgetAll(item);
        System.out.println(stringStringMap);
      });
      return users;
    }
      public static void main(String[] args) {
          for (int i = 0; i <300 ; i++) {
              Cat cat = new Cat();
              cat.setId(i+201800000);
              //cat.setBirthday();


          }*/




